package com.spark.trouble

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.view.View
import com.spark.common.BaseFragment
import com.spark.common.Const
import com.spark.trouble.handle.SpotHandleFragment
import kotlinx.android.synthetic.main.frag_chking.*

/**
 * 审核中
 */
class ChkingFragment : BaseFragment() {
    private lateinit var chkingAdapter: ChkingAdapter

    companion object {
        fun newInstance(): ChkingFragment {
            val target = ChkingFragment()
            val args = Bundle()
            target.arguments = args
            return target
        }
    }

    override fun contentResId(): Int {
        return R.layout.frag_chking
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iv_back.setOnClickListener { pop() }
        tv_title.text = "审核中"

        val tabStr = mutableListOf("现场治理", "现场情况")
        tabStr.forEach {
            tabs.addTab(tabs.newTab().setText(it))
        }
        tabs.setupWithViewPager(pager)
        pager.canScroll = false

        chkingAdapter = ChkingAdapter(childFragmentManager, tabStr)
        pager.adapter = chkingAdapter
    }
}

class ChkingAdapter(fm: FragmentManager, var tabStr: MutableList<String>) : FragmentStatePagerAdapter(fm) {
    override fun getItem(position: Int): Fragment {
        return SpotHandleFragment.newInstance(Const.htTypeProcess,"1")
    }

    override fun getCount(): Int {
        return tabStr.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return tabStr[position]
    }

}